<template>
	<view class="content">
		<uni-search-bar @confirm="searchCityBus" v-model="searchKey" />
		<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in rotateList">
				<view class="swiper-item">
					<image :src="item.img" mode="" style="width: 100%;"></image>
				</view>
			</swiper-item>
		</swiper>
	</view>
	<view class="weather" style="height: 100rpx;border: 1px solid #ccc;margin: 5px; border-radius: 5px;display: flex;justify-content: space-between; padding: 10rpx;align-items: center;
				">
		<view class="icon" style="width: 100rpx;height: 100rpx; ">
			<image style="width: 100%;height: 100%;" :src="'/static/weather/icons/'+ weatherNow.icon +'.svg'" mode="">
			</image>
		</view>
		<view class="text" style="font-size: 50rpx;margin-left: 10px;">
			{{weatherNow.temp}}°C
		</view>
		<view class="text" style="font-size: 34rpx;margin-left: 10rpx;">
			{{weatherNow.text}}
		</view>
		<view class="text" style=" margin-left: 10rpx;">
			{{weatherNow.windDir}} {{weatherNow.windScale}}级
		</view>
		<view>
			<view class="text" style="margin-left: 10rpx;">
				体感温度： {{weatherNow.feelsLike }}°C
			</view>
			<view class="text" style="margin-left: 10rpx;">
				湿度： {{weatherNow.humidity }}%
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		CONFIG
	} from '../../utils/config';
	onLoad(() => {
		getLuinbo()
		getWeather()
	})

	let rotateList = ref([])
	async function getLuinbo() {
		let res = await uni.$get(CONFIG.leancloud_url + "/1.1/classes/xianplay")
		console.log(res)
		rotateList.value = res.results
	}

	let searchKey = ref("")

	function searchCityBus() {
		if (searchKey.value == "") {
			uni.showToast({
				title: "",
				icon: "none"
			})
		} else {
			let url = `https://uri.amap.com/line?name=${searchKey.value}&city=029&src=mypage&callnative=0`
			window.location.href = url
		}
	}
	let weatherNow = ref({})
	async function getWeather() {
		let res = await uni.$get(
			"https://devapi.qweather.com/v7/weather/now?key=26d58fa012e64ec6a9fb8399f1bcf425&location=101110101")
		if (res.code == 200) {
			weatherNow.value = res.now
			console.log(res.now)
		}
	}
</script>

<style>
	/* .content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	} */
</style>